//
//  BaseTabBarViewController.swift
//  SunxianhuaTestApp
//
//  Created by abc on 2021/10/12.
//

import UIKit

class BaseTabBarViewController: UITabBarController {
    
    var sonVCArray :[UIViewController] = Array()
    override func viewWillLayoutSubviews() {
        
        super.viewWillLayoutSubviews()
        
        var tabReact = self.tabBar.frame
        print("-----\(tabReact.height)------")
        
        if !AppConfiguration.isIponex {
            tableBarHeight = 64.0
            tabReact.size.height = tableBarHeight
            for vc in self.sonVCArray {
                vc.tabBarItem.titlePositionAdjustment = UIOffset.init(horizontal: 0, vertical: -8.0)
                vc.tabBarItem.imageInsets = UIEdgeInsets.init(top: -6, left: 0, bottom: 4, right: 0)
            }
        }else{
            tableBarHeight = 83.0
        }
        
        tabReact.origin.y = self.view.frame.size.height - tabReact.size.height
        self.tabBar.frame = tabReact
        
    }
    
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        

        self.tabBar.barTintColor = .white
        self.tabBar.backgroundImage = UIColor.imageWithUIColor(UIColor.white)
        self.tabBar.shadowImage = UIColor.imageWithUIColor(UIColor.white)
        
        
        self.addViewController(viewController: NewsTableVIewController(), title: "新闻", imageName: "home_ico_default", selectImageName: "home_ico_pre")
        
        self.addViewController(viewController: ConfigViewController(), title: "配置", imageName: "my_ico_default", selectImageName: "my_ico_pre")
        
    }


    func addViewController(viewController :UIViewController ,title :String ,imageName :String ,selectImageName :String){
        
        viewController.tabBarItem.tag  = self.sonVCArray.count
        viewController.tabBarItem.title = title
        viewController.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.set_Color(95, green: 195, blue: 243, alpha: 1),NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 12)], for: .selected)
                viewController.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)], for: .normal)
        viewController.tabBarItem.image = UIImage(named: imageName)
        viewController.tabBarItem.selectedImage = UIImage(named: selectImageName)?.withRenderingMode(.alwaysOriginal)
        
        self.sonVCArray.append(viewController)
        let nav = BaseNavigationViewController(rootViewController: viewController)
        self.addChild(nav)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}


